package com.world.business.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.world.business.user.domain.UserKungFu;
import com.world.business.user.domain.query.UserKungFuAddRequest;
import com.world.business.user.domain.query.UserKungFuPageRequest;
import com.world.business.user.domain.query.UserKungFuUpdateRequest;
import com.world.business.user.domain.vo.UserKungFuVO;
import com.world.business.user.service.IUserKungFuService;
import com.world.common.controller.BaseController;
import com.world.common.domain.PageResult;
import com.world.common.domain.ResponseData;
import com.world.common.domain.SuccessResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户所习功法 前端控制器
 * </p>
 *
 * @author 邓驴
 * @since 2023-09-05
 */
@Api(tags = "用户所习功法")
@RestController
@RequestMapping("/user/kungfu")
public class UserKungFuController extends BaseController<UserKungFu> {

    @Resource
    private IUserKungFuService userKungFuService;

    @ApiModelProperty("新增")
    @PostMapping("")
    public ResponseData<Long> add(@Validated @RequestBody UserKungFuAddRequest request) {
        return new SuccessResponseData<>(userKungFuService.add(request));
    }

    @ApiOperation("分页")
    @GetMapping("/page")
    public ResponseData<PageResult<UserKungFuVO>> page(UserKungFuPageRequest request) {
        IPage<UserKungFuVO> page = userKungFuService.getPage(startPage(request), request);
        return new SuccessResponseData<>(getPageResult(page));
    }

    @ApiOperation("修改")
    @PutMapping("")
    public ResponseData<Void> update(@Validated @RequestBody UserKungFuUpdateRequest request) {
        userKungFuService.update(request);
        return new SuccessResponseData<>();
    }

}
